<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel app\modules\admin\models\FormFieldsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Form Fields';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="form-fields-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('Create Form Fields', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],
            'id',
            'tenant',
//            'required_form',
            [
                'attribute'=> "required_form",
                'value'=> function($data){
                    $required_form = json_decode($data->required_form);
                    $data = "";
                    foreach ($required_form as $required => $v){
                       if ($v == "USER_FORM_INFO_FLAG_MOBILE"){
                           $data.= "手机号";
                       }
                        if ($v == "USER_FORM_INFO_FLAG_SEX"){
                            $data.="性别-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_NAME"){
                            $data.="姓名-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_BIRTHDAY"){
                            $data.="生日-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_IDCARD"){
                            $data.="身份证-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_EMAIL"){
                            $data.="邮箱-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_LOCATION"){
                            $data.="详细地址-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_INDUSTRY"){
                            $data.="行业-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_INCOME"){
                            $data.="收入-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_HABIT"){
                            $data.="兴趣爱好-";
                        }
                    }

                    return rtrim($data, "-");;
                }
            ],
//            'optional_form',

            [
                'attribute'=> "optional_form",
                'value'=> function($data){
                    $required_form = json_decode($data->optional_form);
                    $data = "";
                    foreach ($required_form as $required => $v){
                        if ($v == "USER_FORM_INFO_FLAG_MOBILE"){
                            $data.= "手机号";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_SEX"){
                            $data.="性别-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_NAME"){
                            $data.="姓名-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_BIRTHDAY"){
                            $data.="生日-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_IDCARD"){
                            $data.="身份证-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_EMAIL"){
                            $data.="邮箱-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_LOCATION"){
                            $data.="详细地址-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_INDUSTRY"){
                            $data.="行业-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_INCOME"){
                            $data.="收入-";
                        }
                        if ($v == "USER_FORM_INFO_FLAG_HABIT"){
                            $data.="兴趣爱好-";
                        }
                    }

                    return rtrim($data, "-");;
                }
            ],

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>
